package com.mzkj.wanjulaile.mobile.api.modules.category.service;

import com.google.common.collect.Lists;
import com.mzkj.wanjulaile.mobile.api.common.service.CrudService;
import com.mzkj.wanjulaile.mobile.api.modules.category.entity.ProductCategory;
import com.mzkj.wanjulaile.mobile.api.modules.category.entity.SubCategory;
import com.mzkj.wanjulaile.mobile.api.modules.category.mapper.ProductCategoryMapper;
import com.mzkj.wanjulaile.mobile.api.modules.category.mapper.SubCategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 产品分类Service
 * @author ianly
 * @version 2016-10-09
 */
@Service
@Transactional(readOnly = true)
public class ProductCategoryServiceImpl implements ProductCategoryService {

	@Autowired
	private SubCategoryMapper subCategoryMapper;
	@Autowired
	private ProductCategoryMapper productCategoryMapper;

	public List<ProductCategory> findList(ProductCategory productCategory) {
		return productCategoryMapper.findList(productCategory);
	}

	public List<ProductCategory> getAllCategory(){
		List<ProductCategory> list=productCategoryMapper.findList(new ProductCategory());
		List<ProductCategory> categoryList= Lists.newArrayList();
		for(ProductCategory category:list){
			SubCategory subCategory=new SubCategory();
			subCategory.setProductCategory(category);
			category.setSubCategoryList(subCategoryMapper.getSubCategoryByProCategoryId(subCategory));
			categoryList.add(category);
		}
		return categoryList;
	}

}